﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="GovernmentOfficeProject.common.view.ViewPageBase" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
    <title>系统联系人</title>  
    <link rel="stylesheet" type="text/css" href="/lib/easyui/themes/bootstrap/easyui.css"/>  
    <link rel="stylesheet" type="text/css" href="/lib/easyui/themes/icon.css"/>  
    <script type="text/javascript" src="/lib/easyui/jquery-1.8.0.min.js"></script>   
    <script type="text/javascript" src="/lib/easyui/jquery.easyui.min.js"></script>  
    <script type="text/javascript" src="/lib/easyui/plugins/jquery.datagrid.js"></script>  
    <script type="text/javascript" src="/lib/easyui/locale/easyui-lang-zh_CN.js"></script> 

    <script type="text/javascript">
        var buttons = <%= GovernmentOfficeProject.LevelBusinessLogic.BLL_SYSTEM.GetMenuButtonByMneuNoAndUserIdToJsion(
             GovernmentOfficeProject.SysTools.SystemContext.CurrentUserID,Request.QueryString["menuNo"])%>;  
        
        $(document).ready(function () {
            if(buttons.indexOf("add") == -1){
                $("#btn_add").css("display","none");
            }
            if(buttons.indexOf("modify") == -1){
                $("#btn_edit").css("display","none");
            }
            if(buttons.indexOf("delete") == -1){
                $("#btn_del").css("display","none");
            }

            $("#dg").datagrid({height:document.body.clientHeight-11});
            
            
            $.extend($.fn.validatebox.defaults.rules, {
                mobileNumber: {
                    validator: function(value,param) {
                        return /^(1(([35][0-9])|(47)|[8][01236789]))\d{8}$/.test(value);  
                    },message: '请输入正确的手机号码'
                }
            });
        });
        
        var url;  
        function newUser(){  
            $('#dlg').dialog('open').dialog('setTitle','新联系人');  
            $('#fm').form('clear');
            url = '/handler/ContactsDatafeed.ashx?action=add';  
        }  
        function editUser(){
            var row = $('#dg').datagrid('getSelected');
            if (row){  
                $('#dlg').dialog('open').dialog('setTitle','编辑联系人');  
                $('#fm').form('load',row);  
                url = '/handler/ContactsDatafeed.ashx?action=edit&id='+row.Id;  
            }  
        }  
        function saveUser(){  
            $('#fm').form('submit',{  
                url: url,  
                onSubmit: function(){
                    
                    return $(this).form('validate');  
                },  
                success: function(result){  
                    var result = eval('('+result+')');  
                    if (!result.IsSuccess){  
                        $.messager.show({  
                            title: '错误',  
                            msg: result.Msg  
                        });
                    } else {
                        $.messager.show({
                            title: '成功',
                            msg: result.Msg  
                        });  
                        $('#dlg').dialog('close');      // close the dialog
                        $('#dg').datagrid('reload');    // reload the user data
                    }  
                }  
            });  
        }  
        function destroyUser(){  
            var row = $('#dg').datagrid('getSelected');  
            if (row){  
                $.messager.confirm('确认','您确定要删除当前联系人吗?',function(r){  
                    if (r){
                        $.post('/handler/ContactsDatafeed.ashx?action=delete', { id: row.Id }, function(result) {
                            if (result) {
                                $.messager.show({
                                    title: '成功',
                                    msg: '删除成功！'
                                });  
                                $('#dg').datagrid('reload');    // reload the user data  
                            } else {  
                                $.messager.show({   // show error message  
                                    title: '错误',  
                                    msg: '删除失败！'  
                                });  
                            }  
                        },'json');  
                    }  
                });  
            }  
        } 
        
        function searchHandler() {
            $('#dg').datagrid('load', {  
                Name: $("#txt_name").val(),  
                MobileNumber: $("#txt_mobile").val(),
                PhoneNumber:$("#txt_phone").val(),
                Company:$("#txt_company").val()
            });  
        } 
    </script>  
    <style type="text/css">  
        html,body{padding:2px; margin:0;font-family:helvetica,tahoma,verdana,sans-serif;font-size:12px;height:100%;width:100%}
        #fm{  
            margin:0;  
            padding:10px 30px;  
        }  
        .ftitle{  
            font-size:14px;  
            font-weight:bold;  
            padding:5px 0;  
            margin-bottom:10px;  
            border-bottom:1px solid #ccc;  
        }  
        .fitem{  
            margin-bottom:5px;  
        }  
        .fitem label{  
            display:inline-block;  
            width:80px;  
        }  
    </style>  
</head>  
<body>
    <div style="width:100%;height:100%">
    <table id="dg" class="easyui-datagrid" style="width:100%" 
            url="/handler/ContactsDatafeed.ashx?action=list"  
            toolbar="#toolbar" pagination="true" fit="true"
            rownumbers="true" fitColumns="true" singleSelect="true" 
            >  
        <thead>  
            <tr>  
                <th field="Name" width="50">姓名</th>  
                <th field="MobileNumber" width="40">手机</th>  
                <th field="PhoneNumber" width="40">电话</th>
                <th field="FaxNumber" width="40">传真</th>
                <th field="Company" width="50">单位</th>
                <th field="Email" width="50">邮箱</th>
                <th field="Address" width="100%">住址</th>    
            </tr>  
        </thead>  
    </table> 
    </div>   
    <div id="toolbar">
        <div>
            <a href="javascript:void(0)" id="btn_add"  class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">新建</a>  
            <a href="javascript:void(0)" id="btn_edit" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">编辑</a>  
            <a href="javascript:void(0)" id="btn_del" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">删除</a>  
        </div>
        <div>
            姓名 <input id="txt_name" type="text" style="width:100px"/> &nbsp;
            手机 <input id="txt_mobile" type="text" style="width:100px"/> &nbsp;
            电话 <input id="txt_phone" type="text" style="width:100px"/> &nbsp;
            单位 <input id="txt_company" type="text" /> 
            <a href="javascript:void(0)" id="btn_search" onclick="searchHandler()" class="easyui-linkbutton" iconCls="icon-search" >查询</a>  
        </div>
    </div>  
      
    <div id="dlg" class="easyui-dialog" style="width:500px;height:400px;padding:10px 20px"  
            closed="true" buttons="#dlg-buttons">  
        <div class="ftitle">联系人信息</div>  
        <form id="fm" method="post" novalidate>  
            <div class="fitem">  
                <label>姓名</label>  
                <input name="Name" class="easyui-validatebox" data-options="required:true" />  
            </div>  
            <div class="fitem">  
                <label>手机:</label>  
                <input name="MobileNumber" id="MobileNumber" class="easyui-validatebox" data-options="required:true,validType:'mobileNumber'"/>  
            </div> 
            <div class="fitem">  
                <label>电话:</label>  
                <input name="PhoneNumber"/>  
            </div>
             <div class="fitem">  
                <label>单位:</label>  
                <input name="Company"/>  
            </div>
            <div class="fitem">  
                <label>传真:</label>  
                <input name="FaxNumber" />  
            </div>     
            <div class="fitem">  
                <label>邮箱:</label>  
                <input name="Email" class="easyui-validatebox" validType="email"/>  
            </div> 
            <div class="fitem">  
                <label>地址:</label>  
                <input name="Address" style="width:280px;"/>  
            </div>      
        </form>  
    </div>  
    <div id="dlg-buttons">  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser()">保存</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>  
    </div>  
    
</body>  
</html>  